<?php
/**
 * Created by PhpStorm.
 * User: allen
 * Date: 2018/11/16
 * Time: 10:04 PM
 */



$string = pack('L4', 1, 2, 3, 4);
var_dump(unpack('L4', $string));

// 如果a+b+c = 1000且a^2+b^2=c^2,求出所有a,b,c可能的组合
function test($n)
{

    for ($i = 0; $i <= $n; $i++) {
        for ($j = 0; $j <= $n; $j++) {
            /*for($k=1;$k<=$n;$k++){
                if($i+$j+$k == $n && pow($i,2)+pow($j,2)==pow($k,2)){
                    echo sprintf("a:%s,b:%s,c:%s\n",$i,$j,$k);
                }
            }*/
            $k = 1000 - $i - $j;
            if (pow($i, 2) + pow($j, 2) == pow($k, 2)) {
                echo sprintf("a:%s,b:%s,c:%s\n", $i, $j, $k);

            }
        }
    }

}

function test1()
{

    $arr = range(0, 1000);
    foreach ($arr as $v) {
        foreach ($arr as $v1) {
            /*foreach($arr as $v2){
                if($v+$v1+$v2 == 1000 && pow($v,2)+pow($v1,2) == pow($v2,2)){
                    echo sprintf("a:%s,b:%s,c:%s\n",$v,$v1,$v2);

                }
            }*/
            $v2 = 1000 - $v - $v1;
            if (pow($v, 2) + pow($v1, 2) == pow($v2, 2)) {
                echo sprintf("a:%s,b:%s,c:%s\n", $v, $v1, $v2);

            }
        }
    }


}

$s = microtime(true);

//test(1000);

//test1();

$e = microtime(true);

echo (($e - $s) / 3600). "\n";
